import axios from "axios";

export const getWarehousesList = (callback) => {
    axios.get('/warehouse').then((response) => {
        callback(response.data);
    });
}

export const findWarehouseNamesByKeyword = (name, cb) => {
    axios.get('/warehouse/find', {params: {name: name}}).then((response) => {
        let rs = [];
        for (const item of response.data) {
            rs.push({value: item})
        }
        cb(rs);
    })
}


export const getWarehouse = (id, callback) => {
    axios.get('/warehouse/' + id).then((response) => {
        callback(response.data)
    })
}


export const deleteWarehouse = (id, callback) => {
    axios.delete('/warehouse/' + id).then((response) => {
        callback(response.data);
    });
}

export const updateWarehouse = (warehouseData, callback) => {
    axios.put('/warehouse/' + warehouseData.wid, warehouseData).then((response) => {
        callback(response.data ? 1 : 0);
    })
}

export const createWarehouse = (warehouseData, callback) => {
    axios.post('/warehouse', warehouseData).then((response) => {
        callback(response.data ? 1 : 0)
    })
}